home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / misc / wvware-mos.lha / bin / wvPS < prev    next >
Text File  |  2002-05-07  |  7KB  |  316 lines

  1. #!/bin/sh
  2.  
  3. wv_script_name="$0"
  4.  
  5. which latex >/dev/null 2>&1
  6. if [ ${?} -ne "0" ]; then
  7.   echo "Could not find required program 'latex'"
  8.   exit 1
  9. fi
  10.  
  11. which dvips >/dev/null 2>&1
  12. if [ ${?} -ne "0" ]; then
  13.   echo "Could not find required program 'dvips'"
  14.   exit 1
  15. fi
  16.  
  17. prefix=/gg
  18. exec_prefix=
  19. datadir=
  20. t_dir=.
  21.  
  22. wv_opts=
  23. i_file=
  24. o_file=
  25. print_help=no
  26.  
  27. while test $# -gt 0; do
  28.   case "$1" in
  29.   -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  30.   *) optarg= ;;
  31.   esac
  32.  
  33.   case $1 in
  34.     --prefix=*)
  35.       prefix=$optarg
  36.       ;;
  37.     --exec-prefix=*)
  38.       exec_prefix=$optarg
  39.       ;;
  40.     --datadir=*)
  41.       datadir=$optarg
  42.       ;;
  43.     --targetdir=*)
  44.       t_dir=$optarg
  45.       ;;
  46.     --charset=* | --password=*)
  47.       wv_opts="$wv_opts $1"
  48.       ;;
  49.     -v | --version)
  50.       echo 0.7.2
  51.       exit 0
  52.       ;;
  53.     -\? | -h | --help)
  54.       cat << EOF
  55. Usage: $wv_script_name [OPTIONS] <input-file> <output-file>
  56. Options:
  57.       --prefix=<DIR>        Set prefix (default is /gg)
  58.       --exec-prefix=<DIR>   Set exec_prefix (default is ${prefix})
  59.       --datadir=<DIR>       Set datadir (default is ${prefix}/share)
  60.       --targetdir=<DIR>     Target directory (target is <DIR>/<output-file>)
  61.       --charset=<charset>   Specify an iconv charset encoding
  62.       --password=<password> Specify password for encrypted
  63.   -v, --version             Print version info and exit
  64.  
  65. Authors:
  66.   Dom Lachowicz (dominicl@seas.upenn.edu)
  67.   Caolan McNamara (original author)
  68. Visit http://www.wvware.com/
  69. EOF
  70.       exit 0
  71.       ;;
  72.     -?*)
  73.       echo "Option '$1' not recognized."
  74.       exit 1
  75.       ;;
  76.     *)
  77.       if test "x$i_file" = "x"; then
  78.         i_file=$1
  79.       elif test "x$o_file" = "x"; then
  80.         o_file=$1
  81.       else
  82.         echo "Option '$1' not recognized."
  83.         exit 1
  84.       fi
  85.       ;;
  86.   esac
  87.   shift
  88. done
  89.  
  90. if test "x$i_file" = "x-"; then
  91.   echo "error: cannot specify '-' as input"
  92.   exit 1
  93. fi
  94. if test -r "$i_file"; then
  95.   okay=yes
  96. else
  97.   echo "error: '$i_file' unreadable"
  98.   exit 1
  99. fi
  100.  
  101. if test "x$o_file" = "x"; then
  102.   echo "Usage: $1 [OPTIONS] <input-file> <output-file>"
  103.   exit 1
  104. fi
  105. if test "x$i_file" = "x-"; then
  106.   echo "error: cannot specify '-' as output"
  107.   exit 1
  108. fi
  109. name=`basename "$o_file"`
  110. if test "x$o_file" != "x$name"; then
  111.   echo "error: use '--targetdir' for writing in another directory"
  112.   exit 1
  113. fi
  114. name=`basename "$o_file" | sed "s/ /_/g"`
  115. name=`echo $name | sed 's/\.[^\.]*$//'`
  116.  
  117. if test "x$exec_prefix" = "x"; then
  118.   exec_prefix=${prefix}
  119. fi
  120. wv_exec="$exec_prefix/bin/wvWare"
  121. if test -x "$wv_exec"; then
  122.   okay=yes
  123. else
  124.   wv_version=`wvWare -v 2>&1 | cut -f 2 -d " "`
  125.   if test "x$wv_version" = "x0.7.2"; then
  126.     wv_exec="wvWare"
  127.   else
  128.     echo "error: no executable at '$wv_exec' or in path"
  129.     exit 1
  130.   fi
  131. fi
  132.  
  133. if test "x$datadir" = "x"; then
  134.   datadir=${prefix}/share
  135. fi
  136. xmlcfg="$datadir/wv/wvLaTeX.xml"
  137. if test -r "$xmlcfg"; then
  138.   okay=yes
  139. else
  140.   echo "error: '$xmlcfg' unreadable"
  141.   exit 1
  142. fi
  143.  
  144. if test -d "$t_dir"; then
  145.   if test -w "$t_dir"; then
  146.     okay=yes
  147.   else
  148.     echo "error: '$t_dir' is not writable"
  149.     exit 1
  150.   fi
  151. else
  152.   echo "error: '$t_dir' is not a directory"
  153.   exit 1
  154. fi
  155.  
  156. # auto_wmf=`"$wv_exec" --auto-eps=wmf`
  157. # auto_emf=`"$wv_exec" --auto-eps=emf`
  158. # auto_png=`"$wv_exec" --auto-eps=png`
  159. # auto_jpg=`"$wv_exec" --auto-eps=jpg`
  160. # auto_pict=`"$wv_exec" --auto-eps=pict`
  161.  
  162. im_chk=`convert --help 2>&1 | grep -v ImageMagick`
  163. if test "x$im_chk" = "x"; then
  164.   im_chk="no"
  165.   s_img=""
  166. else
  167.   im_chk="yes"
  168. # if we have ImageMagick's convert, then use that to convert PNG, JPEG & PICT
  169. # to EPS. Therefore, need to suppress wvWare's desire to convert these:
  170.   s_img="png,jpg,pict"
  171. fi
  172.  
  173. "$wv_exec" $wv_opts -x "$xmlcfg" -d "$t_dir" -b "$name" "$i_file" -s "$s_img" > "$t_dir"/"$name".tex
  174.  
  175. cd "$t_dir"
  176.  
  177. echo
  178. echo 'Current directory: '`pwd`
  179.  
  180. # First, convert any images
  181.  
  182. i_okay=yes
  183.  
  184. for i_name in "$name"*.wmf; do
  185.   if test -r "$i_name"; then
  186.     e_name=`echo "$i_name" | sed 's/wmf$/eps/'`
  187.     if test -r "$e_name"; then
  188.       echo '"'$e_name'"' exists - skipping...
  189.     else
  190.       if test "$im_chk" = "yes"; then
  191.         convert "$i_name" "$e_name"
  192.         if test -r "$e_name"; then
  193.           echo created '"'$e_name'"'
  194.         else
  195.           echo '"'$i_name'"': conversion failed
  196.           i_okay=no
  197.         fi
  198.       else
  199.         echo unable to convert '"'$i_name'"' '(no converter)'
  200.         i_okay=no
  201.       fi
  202.     fi
  203.   fi
  204. done
  205.  
  206. for i_name in "$name"*.emf; do
  207.   if test -r "$i_name"; then
  208.     e_name=`echo "$i_name" | sed 's/emf$/eps/'`
  209.     if test -r "$e_name"; then
  210.       echo '"'$e_name'"' exists - skipping...
  211.     else
  212.       echo unable to convert '"'$i_name'"' '(no converter)'
  213.       i_okay=no
  214.     fi
  215.   fi
  216. done
  217.  
  218. for i_name in "$name"*.png; do
  219.   if test -r "$i_name"; then
  220.     e_name=`echo "$i_name" | sed 's/png$/eps/'`
  221.     if test -r "$e_name"; then
  222.       echo '"'$e_name'"' exists - skipping...
  223.     else
  224.       if test "$im_chk" = "yes"; then
  225.         convert "$i_name" "$e_name"
  226.         if test -r "$e_name"; then
  227.           echo created '"'$e_name'"'
  228.         else
  229.           echo '"'$i_name'"': conversion failed
  230.           i_okay=no
  231.         fi
  232.       else
  233.         echo unable to convert '"'$i_name'"' '(no converter)'
  234.         i_okay=no
  235.       fi
  236.     fi
  237.   fi
  238. done
  239.  
  240. for i_name in "$name"*.jpg; do
  241.   if test -r "$i_name"; then
  242.     e_name=`echo "$i_name" | sed 's/jpg$/eps/'`
  243.     if test -r "$e_name"; then
  244.       echo '"'$e_name'"' exists - skipping...
  245.     else
  246.       if test "$im_chk" = "yes"; then
  247.         convert "$i_name" "$e_name"
  248.         if test -r "$e_name"; then
  249.           echo created '"'$e_name'"'
  250.         else
  251.           echo '"'$i_name'"': conversion failed
  252.           i_okay=no
  253.         fi
  254.       else
  255.         echo unable to convert '"'$i_name'"' '(no converter)'
  256.         i_okay=no
  257.       fi
  258.     fi
  259.   fi
  260. done
  261.  
  262. for i_name in "$name"*.pict; do
  263.   if test -r "$i_name"; then
  264.     e_name=`echo "$i_name" | sed 's/pict$/eps/'`
  265.     if test -r "$e_name"; then
  266.       echo '"'$e_name'"' exists - skipping...
  267.     else
  268.       if test "$im_chk" = "yes"; then
  269.         convert "$i_name" "$e_name"
  270.         if test -r "$e_name"; then
  271.           echo created '"'$e_name'"'
  272.         else
  273.           echo '"'$i_name'"': conversion failed
  274.           i_okay=no
  275.         fi
  276.       else
  277.         echo unable to convert '"'$i_name'"' '(no converter)'
  278.         i_okay=no
  279.       fi
  280.     fi
  281.   fi
  282. done
  283.  
  284. if test "$i_okay" = "no"; then
  285.   echo 'WARNING: Failed to convert one or more images to EPS'
  286. fi
  287.  
  288. # "$name".tex is the LaTeX file
  289. # use latex to convert this to DVI
  290.  
  291. latex --interaction=batchmode "$name".tex >/dev/null 2>&1
  292.  
  293. # check latex exit status and comment or clean up
  294. if [ ${?} -ne "0" ]; then
  295.     echo "Some problem running latex."
  296.     echo "Check for Errors in $name.log"
  297.     echo "Continuing..."
  298. else
  299.     rm -f "$name".aux "$name".log "$name".tex
  300. fi
  301.  
  302. # latex replaces the "tex" extension with a "dvi" extension
  303. if [ ! -f "$name".dvi ]; then
  304.     echo "Conversion into dvi failed"
  305.     exit 1
  306. fi
  307.  
  308. dvips -o "$o_file" "$name".dvi >/dev/null 2>&1
  309. if [ ${?} -ne "0" ]; then
  310.     echo "Could not convert into Postscript"
  311.     exit 1
  312. fi
  313.  
  314. #clean up
  315. rm -f "$name".dvi
  316.